<template>
  {{ currentTime }}
</template>

<script setup lang="ts">
import {computed, onMounted, onUnmounted, ref} from "vue";
import {webInfoStore} from "@/store";
import {getDiffTime} from "@/utils/date.ts";
const webInfo = webInfoStore()
const runningTime = ref();
let animationFrameId: number;
const animate = () => {
  runningTime.value = Date.now() - Date.parse(webInfo.getDeployTime) ;
  animationFrameId = requestAnimationFrame(animate);
};
onMounted(() => {
  // 开始更新时间
  animationFrameId = requestAnimationFrame(animate);
});
onUnmounted(() => {
  // 停止更新时间
  cancelAnimationFrame(animationFrameId);
});
// 使用计算属性来格式化当前时间
const currentTime = computed(() => {
  return getDiffTime(runningTime.value);
});
</script>

<style scoped lang="less">
/* 这里可以添加你的样式 */
</style>
